// DeepSeek API 测试脚本
const https = require('https');

const apiKey = 'sk-a79c7f1f0b164e2fa559db723804707e';

const testDeepSeekAPI = () => {
  const data = JSON.stringify({
    model: 'deepseek-chat',
    messages: [
      {
        role: 'system',
        content: '你是一位专业的时尚搭配师，擅长根据天气、场合和个人风格提供搭配建议。请用中文回答，语言要专业但易懂。'
      },
      {
        role: 'user',
        content: '请为我推荐一套适合20度晴天的休闲搭配，要求舒适且时尚。'
      }
    ],
    max_tokens: 500,
    temperature: 0.7
  });

  const options = {
    hostname: 'api.deepseek.com',
    port: 443,
    path: '/v1/chat/completions',
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${apiKey}`,
      'Content-Type': 'application/json',
      'Content-Length': data.length
    }
  };

  console.log('🚀 开始测试DeepSeek API...');
  console.log('API密钥:', apiKey.substring(0, 10) + '...');

  const req = https.request(options, (res) => {
    console.log(`状态码: ${res.statusCode}`);
    console.log(`响应头:`, res.headers);

    let responseData = '';

    res.on('data', (chunk) => {
      responseData += chunk;
    });

    res.on('end', () => {
      try {
        const response = JSON.parse(responseData);
        
        if (res.statusCode === 200) {
          console.log('✅ DeepSeek API 调用成功!');
          console.log('📝 AI回复:', response.choices[0].message.content);
          console.log('📊 使用统计:', {
            prompt_tokens: response.usage?.prompt_tokens,
            completion_tokens: response.usage?.completion_tokens,
            total_tokens: response.usage?.total_tokens
          });
        } else {
          console.log('❌ DeepSeek API 调用失败');
          console.log('错误信息:', response);
        }
      } catch (error) {
        console.log('❌ 解析响应失败:', error.message);
        console.log('原始响应:', responseData);
      }
    });
  });

  req.on('error', (error) => {
    console.log('❌ 请求失败:', error.message);
  });

  req.write(data);
  req.end();
};

// 运行测试
testDeepSeekAPI();
